/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.edu.agh.io.gpstracker.model;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * 
 * @author wkedzior
 */
@Entity
@Table(name = "track")
@NamedQueries( {
		@NamedQuery(name = "Track.findAll", query = "SELECT t FROM Track t"),
		@NamedQuery(name = "Track.findById", query = "SELECT t FROM Track t WHERE t.id = :id"),
		@NamedQuery(name = "Track.findByName", query = "SELECT t FROM Track t WHERE t.name = :name"),
		@NamedQuery(name = "Track.findByDistance", query = "SELECT t FROM Track t WHERE t.distance = :distance") })
public class Track implements Serializable {
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Basic(optional = false)
	private Long id;
	@Column(name = "name")
	private String name;
	@Column(name = "distance")
	private Long distance;
	@JoinColumn(name = "user_id", referencedColumnName = "id")
	@ManyToOne(optional = false)
	private User user;
	@OneToMany(cascade = CascadeType.ALL, mappedBy = "track", fetch=FetchType.EAGER)
	private List<Tracksequence> tracksequenceList;

	@Column(name = "user_id", insertable = false, updatable = false)
	private Integer userId;

	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	public Track() {
	}

	public Track(Long id) {
		this.id = id;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Long getDistance() {
		return distance;
	}

	public void setDistance(Long distance) {
		this.distance = distance;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<Tracksequence> getTracksequenceList() {
		return tracksequenceList;
	}

	public void setTracksequenceList(List<Tracksequence> tracksequenceList) {
		this.tracksequenceList = tracksequenceList;
	}

	@Override
	public int hashCode() {
		int hash = 0;
		hash += (id != null ? id.hashCode() : 0);
		return hash;
	}

	@Override
	public boolean equals(Object object) {
		// TODO: Warning - this method won't work in the case the id fields are
		// not set
		if (!(object instanceof Track)) {
			return false;
		}
		Track other = (Track) object;
		if ((this.id == null && other.id != null)
				|| (this.id != null && !this.id.equals(other.id))) {
			return false;
		}
		return true;
	}

	@Override
	public String toString() {
		return "pl.edu.agh.io.gpstracker.model.Track[id=" + id + "]";
	}

}
